prepare(" SELECT r.*, es.student_id, es.exam_id, es.start_time, es.end_time, s.full_name as student_name, s.reg_number, e.name as exam_name, e.year, sub.name as subject_name FROM results r JOIN exam_sessions es ON r.session_id = es.id JOIN students s ON es.student_id = s.id JOIN exams e ON es.exam_id = e.id JOIN subjects sub ON e.subject_id = sub.id WHERE r.session_id = ? "); $stmt->execute([$session_id]); $result = $stmt->fetch(PDO::FETCH_ASSOC); if (!$result) { die("Result not found!"); } // Get all questions and student answers for this session $stmt = $pdo->prepare(" SELECT q.*, sa.selected_answer, sa.is_correct, CASE WHEN sa.selected_answer = 'A' THEN q.option_a WHEN sa.selected_answer = 'B' THEN q.option_b WHEN sa.selected_answer = 'C' THEN q.option_c WHEN sa.selected_answer = 'D' THEN q.option_d ELSE NULL END as selected_option_text, CASE WHEN q.correct_answer = 'A' THEN q.option_a WHEN q.correct_answer = 'B' THEN q.option_b WHEN q.correct_answer = 'C' THEN q.option_c WHEN q.correct_answer = 'D' THEN q.option_d END as correct_option_text FROM questions q LEFT JOIN student_answers sa ON q.id = sa.question_id AND sa.session_id = ? WHERE q.exam_id = ? ORDER BY q.id "); $stmt->execute([$session_id, $result['exam_id']]); $questions = $stmt->fetchAll(PDO::FETCH_ASSOC); // Calculate performance statistics $total_questions = $result['total_questions']; $correct_answers = $result['correct_answers']; $questions_attempted = $result['questions_attempted']; $incorrect_answers = $questions_attempted - $correct_answers; $unattempted = $total_questions - $questions_attempted; $percentage = $result['percentage']; // Get performance level function getPerformanceLevel($percentage) { if ($percentage >= 80) return 'Excellent'; if ($percentage >= 70) return 'Very Good'; if ($percentage >= 60) return 'Good'; if ($percentage >= 50) return 'Average'; if ($percentage >= 40) return 'Pass'; return 'Fail'; } $performance_level = getPerformanceLevel($percentage); ?>
Detailed analysis of student performance
%
/
% Accuracy
/
% Attempt Rate
Exam Duration